module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Answer = app.model.define('Answer', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    FKMergeUserQuestionnaire: {
      type: INTEGER,
      field: 'fk_merge_user_questionnaire'
    },
    FKQuestion: { type: INTEGER, field: 'fk_question' },
    score: { type: INTEGER },
    createdAt: { type: DATE, field: 'created_at' },
    updatedAt: { type: DATE, field: 'updated_at' },
  }, {
    tableName: 'answers'
  });

  Answer.associate = () => {
    app.model.Answer.belongsTo(app.model.MergeUserQuestionnaire, {
      foreignKey: 'fk_merge_user_questionnaire',
      targetKey: 'id',
    });

    app.model.Answer.belongsTo(app.model.Question, {
      foreignKey: 'fk_question',
      targetKey: 'id',
    });
  };

  return Answer;
};
